package cn.hqhy.dish.controller;

import cn.hqhy.dish.pojo.entity.Dish;
import cn.hqhy.dish.service.DishService;
import com.hqhy.like.common.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/dishes")
public class DishController {

    @Autowired
    DishService dishService;

    @PostMapping("/insert")
    public JsonResult insertDish(@RequestBody Dish dish) {
        log.debug("开始添加菜品,参数：{}",dish);

        return JsonResult.ok(dishService.insertDish(dish));
    }//插入菜品


    @PutMapping("/update")
    public JsonResult updateDish(@RequestBody Dish dish) {
        log.debug("开始处理【修改菜品的请求】,菜品:{}",dish);

        return JsonResult.ok(dishService.updateDish(dish));
    }//修改菜品

    @DeleteMapping("/delete/{id}")
    public JsonResult deleteDish(@PathVariable("id") Integer id) {
        log.debug("开始[根据ID删除菜品],参数:{}",id);

        return JsonResult.ok(dishService.deleteDish(id));
    }//删除菜品

    @GetMapping("/get/{id}")
    public JsonResult getDishById(@PathVariable("id") Integer id) {
        log.debug("开始[根据ID查询菜品],参数:{}",id);

        return JsonResult.ok(dishService.getDishById(id));
    }//根据id查询菜品


    @GetMapping("/all")
    public JsonResult getAllDishes() {
        log.debug("开始处理查询所有菜品");
        List<Dish> allDishes = dishService.getAllDishes();
        return JsonResult.ok(allDishes);
    }//查询所有菜品

    @GetMapping("/byName")
    public JsonResult getDishByName(@RequestParam String dish_name) {
        log.debug("开始处理根据菜名查询菜品,参数:{}", dish_name);
        Dish dish = dishService.getDishByName(dish_name);
        return JsonResult.ok(dish);
    }//根据名字查询菜品

    @GetMapping("/byCuisine")
    public JsonResult getDishByCuisine(@RequestParam String dish_cuisine) {
        log.debug("开始处理根据菜系查询菜品,参数:{}", dish_cuisine);
        List<Dish> dishes = dishService.getDishByCuisine(dish_cuisine);
        return JsonResult.ok(dishes);
    }//根据菜系查询菜品


    @GetMapping("/byTaste")
    public JsonResult getDishByTaste(@RequestParam String dish_taste) {
        log.debug("开始处理根据口味查询菜品,参数:{}", dish_taste);
        List<Dish> dishes = dishService.getDishByTaste(dish_taste);
        return JsonResult.ok(dishes);
    }//根据口味查询菜品

    @GetMapping("/byCategory")
    public JsonResult getDishByCategory(@RequestParam String dish_category) {
        log.debug("开始处理根据类型查询菜品,参数:{}", dish_category);
        List<Dish> dishes = dishService.getDishByCategory(dish_category);
        return JsonResult.ok(dishes);
    }//根据荤素类别查询菜品

    @GetMapping("/byRating")
    public JsonResult getDishByRating(@RequestParam Integer dish_rating) {
        log.debug("开始处理根据指数查询菜品,参数:{}", dish_rating);
        List<Dish> dishes = dishService.getDishByRating(dish_rating);
        return JsonResult.ok(dishes);
    }//根据推荐指数查询菜品

    @GetMapping("/byPriceRange")
    public JsonResult getDishByPriceRange(
            @RequestParam BigDecimal minPrice,
            @RequestParam BigDecimal maxPrice) {
        log.debug("开始处理根据价格区间查询菜品,起始值:{},最大值:{}",minPrice,maxPrice);
        List<Dish> dishes = dishService.getDishByPriceRange(minPrice, maxPrice);
        return JsonResult.ok(dishes);
    }//根据价格区间查询菜品

    @GetMapping("/byName2")
    public JsonResult getDishByLikeName(@RequestParam String dish_name) {
        log.debug("开始处理根据菜名模糊查询菜品,参数:{}", dish_name);
        List<Dish> dishes = dishService.getDishByLikeName(dish_name);
        return JsonResult.ok(dishes);
    }

    @GetMapping("/byTaste2")
    public JsonResult getDishByLikeTaste(@RequestParam String dish_taste) {
        log.debug("开始处理根据口味模糊查询菜品,参数:{}", dish_taste);
        List<Dish> dishes = dishService.getDishByLikeTaste(dish_taste);
        return JsonResult.ok(dishes);
    }

    @GetMapping("/byRating2")
    public JsonResult getDishByRating2(@RequestParam int minRating) {
        log.debug("开始处理根据指数区间查询菜品,起始值:{}", minRating);
        List<Dish> dishes = dishService.getDishByRating2(minRating);
        return JsonResult.ok(dishes);
    }
}
